<?php

namespace addons\groupon\controller\store;

use addons\groupon\exception\Exception;
use addons\groupon\controller\Base as GrouponBase;

/**
 * 不继承门店的 base
 */
class Apply extends GrouponBase
{

    protected $noNeedLogin = [];
    protected $noNeedRight = ['*'];


    public function info() {
        $config = new \addons\groupon\model\Config;

        $storeConfig = json_decode($config->where(['name' => 'store'])->value('value'), true);
        $storeConfig['intro_image'] = (isset($storeConfig['intro_image']) && $storeConfig['intro_image']) ? cdnurl($storeConfig['intro_image'], true) : '';

        $this->success('自提点申请', [
            'apply' => \addons\groupon\model\store\Apply::info(),
            'config' => $storeConfig
        ]);
    }


    public function apply() {
        $params = $this->request->post();

        // 表单验证
        $this->grouponValidate($params, get_class(), 'apply');

        $order = \addons\groupon\model\store\Apply::apply($params);

        $this->success('自提点申请提交成功', $order);
    }

}
